#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion

using NUnit.Framework;
using Newtonsoft.Utilities.Reflection;
using Newtonsoft.Utilities.Testing;
using Newtonsoft.Utilities.Miscellaneous;
using System;

namespace Newtonsoft.Utilities.Tests.Reflection
{
  public class OperatorFactoryTests : TestsBase
  {
    [Test]
    public void AddInt()
    {
      Func<int, int, int> add = OperatorFactory.GetAdd<int>();

      Assert.AreEqual(2, add(1, 1));
      Assert.AreEqual(3, add(1, 2));
      Assert.AreEqual(1, add(1, 0));
      Assert.AreEqual(0, add(1, -1));
      Assert.AreEqual(int.MaxValue - 1, add(int.MaxValue, -1));
    }

    [Test]
    public void AddDouble()
    {
      Func<double, double, double> add = OperatorFactory.GetAdd<double>();

      Assert.AreEqual(2.5, add(1.0, 1.5));
      Assert.AreEqual(3.0, add(1.0, 2.0));
      Assert.AreEqual(double.NaN, add(1, double.NaN));
    }

    [Test]
    public void AddDecimal()
    {
      Func<decimal, decimal, decimal> add = OperatorFactory.GetAdd<decimal>();

      Assert.AreEqual(2.5, add(1.0m, 1.5m));
      Assert.AreEqual(3.211, add(1.1m, 2.111m));
    }

    [Test]
    public void MultiplyInt()
    {
      Func<int, int, int> multiply = OperatorFactory.GetMultiply<int>();

      Assert.AreEqual(1, multiply(1, 1));
      Assert.AreEqual(4, multiply(2, 2));
    }

    [Test]
    public void DivideInt()
    {
      Func<int, int, int> divide = OperatorFactory.GetDivide<int>();

      Assert.AreEqual(1, divide(1, 1));
      Assert.AreEqual(2, divide(4, 2));
      Assert.AreEqual(3, divide(9, 3));
      Assert.AreEqual(2, divide(20, 10));
    }

    //[Test]
    //public void MultiplyIntReturnLong()
    //{
    //  Func<int, long, long> multiply = OperatorFactory.GetMultiply<int, long, long>();

    //  Assert.AreEqual(1, multiply(1, 1));
    //  Assert.AreEqual(4, multiply(2, 2));
    //}
  }
}